package com.halixun.d2app.utils;

import android.content.Context;
import android.content.SharedPreferences;

import com.halixun.d2app.app.MyApplication;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

/**
 * @ProjectName: D2App
 * @Package: com.halixun.d2app.utils
 * @ClassName: RunningWaterUtil
 * @Description: java类作用描述
 * @Author: hdx
 * @CreateDate: 2019/12/1 10:53
 * @UpdateUser: hdx
 * @UpdateDate: 2019/12/1 10:53
 * @UpdateRemark: 更新说明：
 * @Version: 1.0
 */
public class RunningWaterUtil {
    private static final String running_water_share = "running_water_share";

    private static final String running_water = "running_water";

    private static SharedPreferences getRunningWaterManager() {
        return MyApplication.getMyContext().getSharedPreferences(running_water_share, Context.MODE_PRIVATE);
    }

    /**
     * 获取本次流水
     * @return
     */
    private static int getRunningWater(){
        return getRunningWaterManager().getInt(running_water,0)+1;
    }



    /**
     * 设置当前流水
     */
    private static void setRunningWater(int currentWater){
        getRunningWaterManager().edit().putInt(running_water,currentWater).commit();
    }

    /**
     * 获取上一次流水
     * @return
     */
    public static int getLastRunningWater(){
        return getRunningWaterManager().getInt(running_water,0);
    }


    /**
     * 重置
     */
    public static void resetRunningWate(){
        getRunningWaterManager().edit().clear().commit();
    }

    /**
     * 获取当前流水
     * @return
     */
    public static String getRunning_water(){
        int currentWater = getRunningWater();
        setRunningWater(currentWater);
        return currentWater+"";
    }
}
